# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
#   cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
#   Mayor.create(name: 'Emanuel', city: cities.first)
user1 = User.create(email: 'test@test.com', name: 'test', password: '123456')
user2 = User.create(email: 'test1@test.com', name: 'test1', password: '123456')
user3 = User.create(email: 'test3@test.com', name: 'test3', password: '123456')
user4 = User.create(email: 'test4@test.com', name: 'test4', password: '123456')
group = Group.create(name: 'test_group', description: 'a test group', owner_id: user1.id)
user1.update(group_id: group.id)
user2.update(group_id: group.id)
user3.update(group_id: group.id)
user4.update(group_id: group.id)

(1..30).each do |i|
  bill_user_id =  rand(1..4)
  bill = Bill.new(name: "test", description: "a test bill", amount: rand(9.9..160.1).round(2), group_id: group.id, user_id: bill_user_id)
  bill.containers.build(user_id: bill_user_id)
  (1..rand(1..4)).each do |j|
    next if j == bill_user_id
    bill.containers.build(user_id: j)
  end
  bill.save!
end
